import book.Library;
import user.NormalUser;
import user.ProxyUser;
import user.User;
import user.factory.AdminUserFactor;
import user.factory.NormalUserFactor;
import user.factory.UserFactor;

import java.lang.reflect.Proxy;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-08-21
 * Time: 12:36
 */
public class LibrarySystem {
    public static void main(String[] args) {
        //利用工厂模式创建对象
        UserFactor adminUserFactor = new AdminUserFactor();
        User adminUser = adminUserFactor.createUser("张三",1);
        UserFactor normalUserFactor = new NormalUserFactor();
        User normalUser1 = normalUserFactor.createUser("李四",2);
        User normalUser2 = normalUserFactor.createUser("王五",3);

        //利用代理类来调用不同对象对应的功能
        ProxyUser proxyAdminUser = new ProxyUser(adminUser);
        ProxyUser proxyNormalUser1 = new ProxyUser(normalUser1);
        ProxyUser proxyNormalUser2 = new ProxyUser(normalUser2);

        LibrarySystem librarySystem = new LibrarySystem();
        //选择不同角色登录
        ProxyUser proxyUser = librarySystem.selectProxyRole(proxyAdminUser, proxyNormalUser1,
                proxyNormalUser2);
        while(true) {
            //根据不同对象选择不同的菜单
            int choice = proxyUser.getRole().showMenu();
            //根据选择的菜单的不同功能来实现不同功能
            proxyUser.handleOperation(choice);
        }
    }

    //选择对应角色进行登录
    public ProxyUser selectProxyRole(ProxyUser proxyAdminUser, ProxyUser proxyNormalUser1,
                                     ProxyUser proxyNormalUser2) {
        System.out.println("请选择对应的角色进行登录:");
        System.out.println("1.管理员\n2.普通用户(李四)\n3.普通用户(王五)\n4.退出系统");
        ProxyUser proxyUser = null;
        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();
        switch (choice) {
            case 1:
                proxyUser = proxyAdminUser;
                break;
            case 2:
                proxyUser = proxyNormalUser1;
                break;
            case 3:
                proxyUser = proxyNormalUser2;
                break;
            case 4:
                System.exit(0);
                System.out.println("系统已退出");
                break;
            default:
                System.out.println("输入错误");
                break;
        }
        return proxyUser;
    }
}
